package handler

import (
	"brand-master/model"
	"github.com/gin-gonic/gin"
	"net/http"
)

func Add(c *gin.Context) {
	title := c.PostForm("title")
	name := c.PostForm("name")
	if title == "" || name == "" {
		c.JSON(http.StatusBadRequest, gin.H{"code": 400,
			"msg": "不能为空"})
		return
	}
	data := model.Act{Title: title, Name: name}
	err := model.DB.Create(&data).Debug().Error
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"code": 400, "msg": "添加失败"})
		return
	}
	c.JSON(http.StatusOK, gin.H{"code": 200, "msg": "添加成功"})
	return
}
func List(c *gin.Context) {
	var art []model.Act
	model.DB.Find(&art).Debug()
	c.JSON(http.StatusOK, gin.H{"code": 200, "data": art, "msg": "展示成功"})
	return

}
